package com.kavenka.zhufengfm.app.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.kavenka.zhufengfm.app.BuildConfig;
import com.kavenka.zhufengfm.app.Constants;
import com.kavenka.zhufengfm.app.R;


public class SplashActivity extends FragmentActivity implements Runnable {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        //1.创建线程停2S
        Thread thread=new Thread(this);
        thread.start();
    }
    @Override
    public void run() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //2.主界面，判断如果当前版本启动过，直接进入应用界面，否者进入功能介绍界面
        SharedPreferences sp = getSharedPreferences(Constants.SP_APP_NAME, MODE_PRIVATE);
        String currentVersion = sp.getString(Constants.SP_CURRENT_VERSION, null);
        Intent intent=null;
        //3.如和当前版本是一样的，则进入mainActivity，不相同进入WelcomeActivity
        if (BuildConfig.VERSION_NAME.equals(currentVersion)){
            intent =new Intent(SplashActivity.this, MainActivity.class);
        }else {
            intent=new Intent(SplashActivity.this, WelcomeActivity.class);
        }
        startActivity(intent);
        finish();//进入了界面，返回键不能再回退到扉页
    }
}
